package LeetCode.LeetCode2;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lumin
 * @date 2022/05/05 15:00
 **/
class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
};
public class Num690 {
    public int DFS(Map<Integer,Employee> info ,int id){
        Employee curE = info.get(id);
        int sum = curE.importance;
        for (int subId:curE.subordinates){
            sum += DFS(info,subId);
        }
        return sum;
    }
    public int getImportance(List<Employee> employees, int id) {
        if(employees.isEmpty()){
            return 0;
        }
        Map<Integer,Employee> info = new HashMap<>();
        for (Employee e: employees){
            info.put(e.id,e);
        }
        return DFS(info,id);
    }
}